function createPosition(a, b) {
    var c = $(parent.window.document.getElementById(a));
    c.html(b);
}

function TabView(a) {
    function h(a) {
        var f, g, h, e = $(a);
        tabTotalWidth = tabTotalWidth + $(e).width() + 5, containerWidth = $("#" + c.containerId).width(), 
        tabTotalWidth + 34 > containerWidth && (pos = containerWidth - tabTotalWidth - 34, 
        $trueContainer.css("left", pos), $btnLeft.fadeIn(200), $btnRight.fadeIn(200)), f = $(e).find(".tab_item1" + d), 
        g = $(e).find(".tab_item2" + d), h = $(e).find(".tab_item3" + d), (null == b.current || b.current != this) && ($(e).mouseover(function() {
            f.addClass("tab_item1_mouseover" + d), g.addClass("tab_item2_mouseover" + d), h.addClass("tab_item3_mouseover" + d);
        }).mouseout(function() {
            f.removeClass("tab_item1_mouseover" + d), g.removeClass("tab_item2_mouseover" + d), 
            h.removeClass("tab_item3_mouseover" + d);
        }).click(function() {
            null != b.current && ($(b.current).find(".tab_item1" + d).removeClass("tab_item1_selected" + d), 
            $(b.current).find(".tab_item2" + d).removeClass("tab_item2_selected" + d), $(b.current).find(".tab_item3" + d).removeClass("tab_item3_selected" + d), 
            $(b.current).find(".tab_close").addClass("tab_close_noselected")), f.addClass("tab_item1_selected" + d), 
            g.addClass("tab_item2_selected" + d), h.addClass("tab_item3_selected" + d), b.current = this, 
            $(b.current).find(".tab_close").removeClass("tab_close_noselected"), i($(this).attr("id"), !1);
        }), "_bottom" == d ? $(e).bind("contextmenu", function(a) {
            return currentTabId = $(this).attr("id"), tabMenu2.show({
                top: a.pageY - 80,
                left: a.pageX
            }), !1;
        }) : $(e).bind("contextmenu", function(a) {
            return currentTabId = $(this).attr("id"), tabMenu.show({
                top: a.pageY,
                left: a.pageX
            }), !1;
        }), $(e).find(".tab_close").mouseover(function() {
            $(this).addClass("tab_close_mouseover");
        }).mouseout(function() {
            $(this).removeClass("tab_close_mouseover");
        }).click(function() {
            j(e.attr("id"));
        }));
    }
    function i(a, d) {
        b.current_page && b.current_page.hide(), b.current_page = $("#page_" + a), b.current_page.show(), 
        c.action($("#" + a), b.current_page), $("body").trigger("dynamicTabActived", a);
    }
    function j(a) {
        var e, f, c = $("#page_" + a), d = $("#" + a);
        tabTotalWidth = tabTotalWidth - d.width() - 5, $(b.current).attr("id") == d.attr("id") && (e = d.next(), 
        e.attr("id") ? $("#" + e.attr("id")).trigger("click") : (f = d.prev(), f.attr("id") && $("#" + f.attr("id")).trigger("click"))), 
        c.remove(), d.remove(), containerWidth > tabTotalWidth + 62 && (pos = 2, $trueContainer.css("left", pos), 
        $btnLeft.fadeOut(200), $btnRight.fadeOut(200)), $("body").trigger("dynamicTabClose", a);
    }
    var b, c, d, e, f, g;
    tabMenu = $.rightClickMenu({
        top: 100,
        left: 100,
        width: 120,
        items: [ {
            text: uncompile(quiLanguage.dynamicTab.tabMenu1),
            click: tabMenuItemClick,
            id: 1
        }, {
            line: !0
        }, {
            text: uncompile(quiLanguage.dynamicTab.tabMenu2),
            click: tabMenuItemClick,
            id: 2
        }, {
            text: uncompile(quiLanguage.dynamicTab.tabMenu3),
            click: tabMenuItemClick,
            id: 3
        } ]
    }), tabMenu2 = $.rightClickMenu({
        top: 100,
        left: 100,
        width: 120,
        items: [ {
            text: uncompile(quiLanguage.dynamicTab.tabMenu3),
            click: tabMenuItemClick,
            id: 3
        }, {
            text: uncompile(quiLanguage.dynamicTab.tabMenu2),
            click: tabMenuItemClick,
            id: 2
        }, {
            line: !0
        }, {
            text: uncompile(quiLanguage.dynamicTab.tabMenu1),
            click: tabMenuItemClick,
            id: 1
        } ]
    }), b = {
        current: null,
        current_index: 0,
        current_page: null
    }, c = new TabOption(), $.extend(c, a), d = "bottom" == c.position ? "_bottom" : "", 
    this.id = c.cid, this.pid = c.pageid, this.tabs = null, this.tabContainer = null, 
    this.iframeScroller = c.iframeScroller, e = '<table class="tab_item"  id="{0}" border="0" cellpadding="0" cellspacing="0"><tr><td class="tab_item1"></td><td class="tab_item2 tab_title">{1}</td><td class="tab_item2"><div class="tab_close"></div></td><td class="tab_item3"></td></tr></table>', 
    f = '<div class="benma_ui_tab" id="{0}"><div class="tab_hr"></div></div>', g = '<iframe id="{0}" name="{3}" {2} allowTransparency="true" frameborder="0" width="100%" height="100%" src="{1}"></iframe>', 
    "bottom" == c.position && (e = '<table class="tab_item_bottom"  id="{0}" border="0" cellpadding="0" cellspacing="0"><tr><td class="tab_item1_bottom"></td><td class="tab_item2_bottom tab_title">{1}</td><td class="tab_item2_bottom"><div class="tab_close tab_close_bottom"></div></td><td class="tab_item3_bottom"></td></tr></table>', 
    f = '<div class="benma_ui_tab benma_ui_tab_bottom" id="{0}"><div class="tab_hr tab_hr_bottom"></div></div>'), 
    $("#" + c.containerId).append(f.replace("{0}", this.id)), $trueContainer = $('<div class="tabContainer"></div>'), 
    $btnLeft = $('<div class="tabButtonLeft" style="display:none;"></div>'), $btnRight = $('<div class="tabButtonRight" style="display:none;"></div>'), 
    $("#" + c.containerId).find(".benma_ui_tab").append($trueContainer), $("#" + c.containerId).find(".benma_ui_tab").append($btnLeft), 
    $("#" + c.containerId).find(".benma_ui_tab").append($btnRight), containerWidth = $("#" + c.containerId).width(), 
    $(window).bind("resize", function() {
        containerWidth = $("#" + c.containerId).width(), containerWidth = $("#" + c.containerId).width(), 
        tabTotalWidth + 34 > containerWidth && (pos = containerWidth - tabTotalWidth - 34, 
        $trueContainer.css("left", pos), $btnLeft.fadeIn(200), $btnRight.fadeIn(200)), containerWidth > tabTotalWidth + 62 && (pos = 2, 
        $trueContainer.css("left", pos), $btnLeft.fadeOut(200), $btnRight.fadeOut(200));
    }), $btnLeft.bind("mousedown", function() {
        containerWidth = $("#" + c.containerId).width(), timer = setInterval(function() {
            return pos > 16 ? (pos = 16, clearInterval(timer), void 0) : (pos += 8, $trueContainer.css("left", pos), 
            void 0);
        }, 30);
    }), $btnLeft.bind("mouseup", function() {
        clearInterval(timer);
    }), $btnRight.bind("mousedown", function() {
        containerWidth = $("#" + c.containerId).width(), timer = setInterval(function() {
            return pos > 16 ? (pos = 16, clearInterval(timer), void 0) : containerWidth - tabTotalWidth - 34 > pos ? (pos = containerWidth - tabTotalWidth - 34, 
            clearInterval(timer), void 0) : (pos -= 8, $trueContainer.css("left", pos), void 0);
        }, 30);
    }), $btnRight.bind("mouseup", function() {
        clearInterval(timer);
    }), this.init = function() {
        this.tabContainer = $("#" + this.id), this.tabs = this.tabContainer.find(".tab_item" + d), 
        this.tabs.each(function() {
            h(this);
        });
    }, this.add = function(a) {
        var d, f, b = new TabItemOption();
        if ($.extend(b, a), $("#" + b.id).length > 0) {
            $("#" + b.id).trigger("click");
            try {
                closeProgress();
            } catch (c) {}
        } else b.title.length > 10 && (b.title = b.title.substring(0, 10)), b.title.length < 4 && (b.title = "&nbsp;&nbsp;" + b.title + "&nbsp;"), 
        d = "" == b.iframeAddtion ? g.replace("{0}", "page_" + b.id).replace("{3}", "page_" + b.id).replace("{1}", b.url).replace("{2}", "") : g.replace("{0}", "page_" + b.id).replace("{3}", "page_" + b.id).replace("{1}", b.url).replace("{2}", b.iframeAddtion), 
        $("#" + this.pid).append(d), f = e.replace("{0}", b.id).replace("{1}", b.title), 
        this.tabContainer.find(".tabContainer").append(f), h($("#" + b.id)), b.isClosed || ($("#" + b.id).find(".tab_close").hide(), 
        $("#" + b.id).attr("closeable", "false"), $("#page_" + b.id).attr("closeable", "false")), 
        $("#" + b.id).trigger("click");
    }, this.update = function(a) {
        var b = a.id;
        $("#" + b).find(".tab_title").html(a.title), $("#" + b).trigger("click"), $("#page_" + b).attr("src", a.url);
    }, this.activate = function(a) {
        $("#" + a).trigger("click");
    }, this.close = function(a) {
        j(a);
    }, this.init();
}

function closeOtherDynamicTab(a) {
    $("#" + a).trigger("click"), $("#" + a).prevAll().each(function() {
        "false" == $(this).attr("closeable") || (tabTotalWidth = tabTotalWidth - $(this).width() - 5, 
        $(this).remove());
    }), $("#" + a).nextAll().each(function() {
        "false" == $(this).attr("closeable") || (tabTotalWidth = tabTotalWidth - $(this).width() - 5, 
        $(this).remove());
    }), $("#page_" + a).prevAll().each(function() {
        "false" == $(this).attr("closeable") || $(this).remove();
    }), $("#page_" + a).nextAll().each(function() {
        "false" == $(this).attr("closeable") || $(this).remove();
    }), containerWidth > tabTotalWidth + 62 && (pos = 2, $trueContainer.css("left", pos), 
    $btnLeft.fadeOut(200), $btnRight.fadeOut(200)), $("body").trigger("dynamicTabCloseOther", a);
}

function closeAllDynamicTab(a) {
    $("#" + a).parent().find(">table").each(function() {
        "false" == $(this).attr("closeable") ? $(this).trigger("click") : (tabTotalWidth = tabTotalWidth - $(this).width() - 5, 
        $(this).remove());
    }), $("#page_" + a).parent().find(">iframe").each(function() {
        "false" == $(this).attr("closeable") || $(this).remove();
    }), containerWidth > tabTotalWidth + 62 && (pos = 2, $trueContainer.css("left", pos), 
    $btnLeft.fadeOut(200), $btnRight.fadeOut(200)), $("body").trigger("dynamicTabCloseAll");
}

function iframeClickHandler() {
    tabMenu.hide(), tabMenu2.hide();
}

function tabMenuItemClick(a) {
    1 == a.id ? document.getElementById("page_" + currentTabId).contentWindow.location.reload() : 2 == a.id ? closeOtherDynamicTab(currentTabId) : 3 == a.id && closeAllDynamicTab(currentTabId);
}

var TabItemOption, pos, timer, tabTotalWidth, $trueContainer, $btnLeft, $btnRight, containerWidth, tabMenu, currentTabId, positionType = "none", positionContent = "", TabOption = function() {};

TabOption.prototype = {
    containerId: "",
    pageid: "",
    cid: "",
    position: top,
    action: function() {}
}, TabItemOption = function() {}, TabItemOption.prototype = {
    id: "tab_",
    title: "",
    url: "",
    iframeAddtion: "",
    isClosed: !0
}, pos = 2, tabTotalWidth = 0, containerWidth = 0;